package com.test.pageObjects;

import com.test.browser.BasePage;
import org.apache.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class LoginPage extends BasePage {
    private static Logger log =Logger.getLogger(LoginPage.class);

    private WebDriver driver;

    public LoginPage(WebDriver driver) {
        super(driver);
    }

    // 元素定位
    // 手机号输入框
    private By phoneInput = By.xpath("//*[@id=\"pane-account\"]/form/div[3]/div/div/input");

    // 密码输入框
    private By passwordInput = By.xpath("//*[@id=\"pane-account\"]/form/div[4]/div/div/input");

    // 登录按钮
    private By loginButton = By.xpath("//*[@id=\"pane-account\"]/form/button");

    // 手机号错误信息
    private By phoneError = By.xpath("//*[@id=\"pane-account\"]/form/div[3]/div/div[2]");

    // 密码错误信息
    private By passwordError = By.xpath("//*[@id=\"pane-account\"]/form/div[4]/div/div[2]");

    // 页面错误信息
    private By errorMessage = By.xpath("/html/body/div[7]/p");

    // 业务逻辑和操作方法
    // 登录方法
    public void login(String phone,String password) {
        sendKeys(phoneInput,phone);
        sendKeys(passwordInput,password);
        click(loginButton);
    }

    // 输入电话号
    public void inputPhone(String phone){
        sendKeys(phoneInput,phone);
    }

    // 输入密码
    public void inputPassword(String password){
        sendKeys(passwordInput, password);
    }

    // 点击登录按钮
    public void clickLogin(){
        click(loginButton);
    }


    // 获取手机号错误信息
    public String getPhoneError(){
        return getText(phoneError);
    }

    // 获取密码错误信息
    public String getPasswordError(){
        return getText(passwordError);
    }

    // 获取页面错误信息
    public String getError(){
        return getText(errorMessage);
    }
}
